package com.evil.mi.controller;

import com.evil.mi.bean.ResultBean;
import com.evil.mi.entity.PageEntity;
import com.evil.mi.entity.VideoEntity;
import com.evil.mi.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * com.evil.mi.controller
 *
 * @author 白雨浓
 * date: 2018/9/5 18:33
 * content:
 */
@RestController
@RequestMapping("/video/rest")
public class VideoRestController {

    @Autowired
    private VideoService videoService;

    @GetMapping("/list/{current}")
    public ResultBean getVideoList(@PathVariable int current) throws InterruptedException {
        PageEntity<VideoEntity> pageEntity = videoService.findVideoPage(current, 10);

        Thread.sleep(new Random().nextInt(30) * 100);

        if (current == -1) {
            return ResultBean.builder().code("-1").success(false).data(null).msg("参数错误").build();
        }

        return ResultBean.builder().code("1").success(true).data(pageEntity).build();
    }

}
